﻿var zombies = zombies || {};

zombies.changepass = function () {
    var self = this;

    self.OldPassword = ko.observable();
    self.NewPassword = ko.observable();

    self.doChange = function (formElement) {
        var data = {
            OldPassword: self.OldPassword(),
            NewPassword: self.NewPassword()
        };
        if ($(formElement).valid()) {
            $.ajax({
                type: "POST",
                url: "/api/Account/ChangePass",
                data: ko.toJSON(data), //Convert the Observable Data into JSON
                contentType: "application/json",
                dataType: 'json'
            }).done(function () {
                toastr.success('Sửa Mật Khẩu Thành Công');
            }).fail(function (request) {
                var msg = request.responseText.substring(12);
                msg = msg.substring(0, msg.length - 2);
                toastr.error(msg);
            });
        }
    };
};

var changepassModel;
$(document).ready(function () {
    changepassModel = new zombies.changepass();

    ko.applyBindings(changepassModel, document.getElementById("content_publisher"));
});